﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Collections.Generic;
using STT.Entities;
using STT.DataAccess;

namespace STT.Business
{
    public class BTbQuyen
    {
        public static DataTable SelectAll()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbQuyen_SelectAll2", null);
            return all;
        }
        public static DataTable SelectAll2()
        {
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbQuyen_GetAll", null);
            return all;
        }
        //-----------------------------------------------------------//
        public static void UpdateTrangThai(string Maquyen, string TrangThai)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"MaQuyen", int.Parse(Maquyen));
            pr[1] = new SqlParameter(@"TrangThai", int.Parse(TrangThai));
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "[TbQuyen_UpdateTT]", pr);
        }

        public static void Insert(ETbQuyen OTbQuyen)
        {
            SqlParameter[] pr = new SqlParameter[2];
            pr[0] = new SqlParameter(@"TenQuyen", OTbQuyen.TenQuyen);
            pr[1] = new SqlParameter(@"TrangThai", OTbQuyen.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbQuyen_Insert", pr);
        }
        //-----------------------------------------------------------//
        public static void Update(ETbQuyen OTbQuyen)
        {
            SqlParameter[] pr = new SqlParameter[3];
            pr[0] = new SqlParameter(@"MaQuyen", OTbQuyen.MaQuyen);
            pr[1] = new SqlParameter(@"TenQuyen", OTbQuyen.TenQuyen);
            pr[2] = new SqlParameter(@"TrangThai", OTbQuyen.TrangThai);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbQuyen_Update", pr);
        }
        //-----------------------------------------------------------//
        public static void Delete(int MaQuyen)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaQuyen", MaQuyen);
            SqlHelper.ExecuteNonQuery(CommandType.StoredProcedure, "TbQuyen_Delete", pr);
        }
        //-----------------------------------------------------------//

        public static bool KiemTraDuLieu(ETbQuyen Quyen)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenQuyen", Quyen.TenQuyen);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbQuyen_KiemTraDuLieu", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        public static bool KiemTraMaQuyen(ETbQuyen Quyen)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"MaQuyen", Quyen.MaQuyen);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbQuyen_KiemTraMaQuyen", pr);
            if (all.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        //-----------------------------------------------------------//
        public static DataTable SearchQuyen(ETbQuyen Quyen)
        {
            SqlParameter[] pr = new SqlParameter[1];
            pr[0] = new SqlParameter(@"TenQuyen", Quyen.TenQuyen);
            DataTable all = SqlHelper.ExecuteData(CommandType.StoredProcedure, "TbQuyen_Search", pr);
            return all;
        }
        //-----------------------------------------------------------//
    }
}